package com.app.service;

import com.alibaba.fastjson.JSON;
import com.app.domain.UploadParameter;
import com.app.domain.YjData;
import com.app.domain.cxlq.TokenData;
import com.app.domain.ldpf.YjSingle;
import com.app.domain.wxgd.WxgdResponseResult;
import com.app.domain.wxjjeb.UploadDataYJ;
import com.app.domain.wxjjeb.WxjjebData;
import com.app.domain.wxjjeb.WxjjebResponseResult;
import com.app.utils.HttpClients;
import com.app.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


/**
 * @author ：wangyu
 * @date ：Created in 2025/8/23 10:06
 * 无锡交建二标
 */
@Service
@Transactional
public class WxjjebService {

    public UploadDataYJ getData(YjData yjData, UploadParameter uploadParameter, String uuid, String equNum, String projectId) {
        UploadDataYJ yjSingle = new UploadDataYJ();
        if (org.springframework.util.StringUtils.isEmpty(uuid)) {
            yjSingle.setUuId(UUID.randomUUID().toString().replace("-", ""));
        } else {
            yjSingle.setUuId(uuid);
        }
        yjSingle.setEquNum(equNum);
        yjSingle.setProjectId(projectId);
        yjSingle.setComponentId(yjSingle.getUuId());
        yjSingle.setEngineeringName(uploadParameter.getGcmc());
        yjSingle.setEngineeringSite(uploadParameter.getSgbw());
        yjSingle.setComponentParts(yjData.getBridge_code()+"/wbscs01");
        yjSingle.setBeamType(uploadParameter.getLblx());
        yjSingle.setConcreteStrength(uploadParameter.getConcretestrength());
        yjSingle.setModulusOfElasticity(uploadParameter.getPumppressure());
        yjSingle.setBridgeName(uploadParameter.getEquipmentname());
        yjSingle.setTrialDate(yjData.getMudjack_date() + " " + yjData.getBegin_time());
        List<WxjjebData> wxgdDataList = new ArrayList<>();
        WxjjebData wxgdData = new WxjjebData();
        wxgdData.setSteelBeamNo(yjData.getDuct_code());
        wxgdData.setSteelStrand(uploadParameter.getKongdaoshu());
        wxgdData.setPulpingOrientation(uploadParameter.getYajiangfangxiang());
        wxgdData.setPulpingOrder(uploadParameter.getYajiangbuzhou());
        wxgdData.setFlowVelocity(uploadParameter.getMsl());
        wxgdData.setFluidity(yjData.getPractical_fluidity());
        wxgdData.setMixProportion(uploadParameter.getPhb());
        wxgdData.setWaterRatio(String.valueOf(yjData.getWater_binder_ratio()));
        wxgdData.setStirringTime(uploadParameter.getStirtime());
        wxgdData.setStartDate(yjData.getMudjack_date() + " " + yjData.getBegin_time());
        wxgdData.setEndDate(yjData.getMudjack_date() + " " + yjData.getEnd_time());
        wxgdData.setPulpingVolume(String.valueOf(yjData.getPractical_mudjack_value()));
        wxgdData.setStandardVolume(uploadParameter.getVolume());
        wxgdData.setPulpingPressureIn(String.valueOf(yjData.getMudjack_pressure()));
        wxgdData.setPulpingPressureOut(String.valueOf(yjData.getSlurry_pressure()));
        wxgdData.setHoldingTime(yjData.getPressurize_time());
        wxgdData.setVolumeCurve("0");
        wxgdData.setPressureinCurve(yjData.getMudjack_curve_graph().replaceAll("-", ","));
        wxgdData.setPressureoutCurve("0");
        wxgdData.setResult("0");
        wxgdData.setUserId(uploadParameter.getBeiyong());
        wxgdData.setOtherInformation("/");
        wxgdData.setParentId(yjSingle.getUuId());
        wxgdData.setUuId(UUID.randomUUID().toString().replace("-", ""));
        wxgdDataList.add(wxgdData);
        yjSingle.setDataList(wxgdDataList);
        return yjSingle;
    }

    public UploadDataYJ getData1(YjData yjData, UploadParameter uploadParameter, String uuid, String equNum, String projectId) {
        UploadDataYJ yjSingle = new UploadDataYJ();
        if (org.springframework.util.StringUtils.isEmpty(uuid)) {
            yjSingle.setUuId(UUID.randomUUID().toString().replace("-", ""));
        } else {
            yjSingle.setUuId(uuid);
        }
        yjSingle.setEquNum(equNum);
        yjSingle.setProjectId(projectId);
        yjSingle.setComponentId(yjSingle.getUuId());
        yjSingle.setEngineeringName(uploadParameter.getGcmc());
        yjSingle.setEngineeringSite(uploadParameter.getSgbw());
        yjSingle.setComponentParts(yjData.getBridge_code());
        yjSingle.setBeamType(uploadParameter.getLblx());
        yjSingle.setConcreteStrength(uploadParameter.getConcretestrength());
        yjSingle.setModulusOfElasticity(uploadParameter.getPumppressure());
        yjSingle.setBridgeName(uploadParameter.getEquipmentname());
        yjSingle.setTrialDate(yjData.getMudjack_date() + " " + yjData.getBegin_time());
        List<WxjjebData> wxgdDataList = new ArrayList<>();
        WxjjebData wxgdData = new WxjjebData();
        wxgdData.setSteelBeamNo(yjData.getDuct_code());
        wxgdData.setSteelStrand(uploadParameter.getKongdaoshu());
        wxgdData.setPulpingOrientation(uploadParameter.getYajiangfangxiang());
        wxgdData.setPulpingOrder(uploadParameter.getYajiangbuzhou());
        wxgdData.setFlowVelocity(uploadParameter.getMsl());
        wxgdData.setFluidity(yjData.getPractical_fluidity());
        wxgdData.setMixProportion(uploadParameter.getPhb());
        wxgdData.setWaterRatio(String.valueOf(yjData.getWater_binder_ratio()));
        wxgdData.setStirringTime(uploadParameter.getStirtime());
        wxgdData.setStartDate(yjData.getMudjack_date() + " " + yjData.getBegin_time());
        wxgdData.setEndDate(yjData.getMudjack_date() + " " + yjData.getEnd_time());
        wxgdData.setPulpingVolume(String.valueOf(yjData.getPractical_mudjack_value()));
        wxgdData.setStandardVolume(uploadParameter.getVolume());
        wxgdData.setPulpingPressureIn(String.valueOf(yjData.getMudjack_pressure()));
        wxgdData.setPulpingPressureOut(String.valueOf(yjData.getSlurry_pressure()));
        wxgdData.setHoldingTime(yjData.getPressurize_time());
        wxgdData.setVolumeCurve("0");
        wxgdData.setPressureinCurve(yjData.getMudjack_curve_graph().replaceAll("-", ","));
        wxgdData.setPressureoutCurve("0");
        wxgdData.setResult("0");
        wxgdData.setUserId(uploadParameter.getBeiyong());
        wxgdData.setOtherInformation("/");
        wxgdData.setParentId(yjSingle.getUuId());
        wxgdData.setUuId(UUID.randomUUID().toString().replace("-", ""));
        wxgdDataList.add(wxgdData);
        yjSingle.setDataList(wxgdDataList);
        return yjSingle;
    }

    public WxjjebResponseResult sendMessage(String serviceUrl, UploadDataYJ yjSingle, String source, String token) {
        String requestJson = JSON.toJSONString(yjSingle);
        WxjjebResponseResult sqResponseResult = null;
        try {
            String result = HttpClients.requestPost(serviceUrl, requestJson, null, source, token);
            sqResponseResult = (WxjjebResponseResult) JSON.parseObject(StringUtil.replaceBlank(result), WxjjebResponseResult.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sqResponseResult;
    }
}
